package com.stmt.analytic.graph.algorithm;

import java.util.ArrayList;
import java.util.function.Function;

public class AdjacencyMatrix {


    private int[][] out;

    private int[][] in;

    private int[][] both;

    public AdjacencyMatrix(ArrayList<Integer>[] matrix) {
        final int length = matrix.length;
        both = new int[length][];
        for (int i = 0; i < length; i++) {
            int neighborSize = matrix[i].size();
            int[] neighbors = new int[neighborSize];
            for (int j = 0; j < neighborSize; j++) {
                neighbors[j] = matrix[i].get(j);
            }
            both[i] = neighbors;
        }
    }

    public int[] armBoth(int vid) {
        return both[vid];
    }

    public int armBothSize(int vid) {
        return both[vid] == null ? 0 : both[vid].length;
    }

    public <R> R map(int vid, Function<Integer, R> function) {
        return function.apply(vid);
    }
}
